'use strict'

const originalOpen = XMLHttpRequest.prototype.open;
const originalSend = XMLHttpRequest.prototype.send;

XMLHttpRequest.prototype.open = function(method, url) {
    this._url = url;
    originalOpen.apply(this, arguments);
};

XMLHttpRequest.prototype.send = function(body) {
    const oldOnLoad = this.onload;

    this.onload = function() {
        if (this._url.includes('https://surveyflow-api.innovatemr.net/api/v1/respondent/getTransactionDetails')) {
            try {
                let response = JSON.parse(this.responseText);

                // 修改 Respondent 信息
                if (response.data && response.data.smplChnResp && response.data.smplChnResp.Respondent) {
                  response.data.smplChnResp.Respondent.threat_potential = "low";
                  response.data.smplChnResp.Respondent.threat_potential_score = 15;
                  response.data.smplChnResp.Respondent.respondent_risk = 0;
                }

                // 修改 Surveys 信息
                if (response.data && response.data.smplChnResp && response.data.smplChnResp.Surveys && response.data.smplChnResp.Surveys.length > 0) {
                  response.data.smplChnResp.Surveys[0].duplicate_score = 0;
                  response.data.smplChnResp.Surveys[0].duplicate_potential = "low";
                  response.data.smplChnResp.Surveys[0].failure_reason = "";
                }

                // 让 responseText 可修改
                const modifiedResponse = JSON.stringify(response);
                Object.defineProperty(this, 'response', { value: modifiedResponse, configurable: true });
                Object.defineProperty(this, 'responseText', { value: modifiedResponse, configurable: true });

            } catch (e) {
                console.error('Failed to parse or modify response', e);
            }
        }

        if (oldOnLoad) {
            oldOnLoad.apply(this, arguments);
        }
    };

    originalSend.call(this, body); // 使用修改后的 body 发送请求
};

console.log("XHR beasurveytaker interceptor installed");




;(self.webpackChunksurveyFlow = self.webpackChunksurveyFlow || []).push([
  [756],
  {
    9756: (T, y, h) => {
      h.r(y), h.d(y, { SecurityCheckModule: () => I })
      var m = h(668),
        f = h(177),
        P = h(5312),
        i = h(4438),
        v = h(3783)
      const g = [
        {
          path: '',
          component: (() => {
            class d {
              constructor(r, t, o, e) {
                ;(this.router = r),
                  (this.route = t),
                  (this.sharedService = o),
                  (this.document = e),
                  (this.env = P.c.innovate),
                  (this.isCleanIdRespExist = !1),
                  (this.isCleanIdTimeoutErr = !1)
              }
              ngOnInit() {
                if (
                  ((this.urlPath = window.location.href),
                  (this.splitUrlPath = this.urlPath.split('?')),
                  (this.routeParams = new URLSearchParams(this.splitUrlPath[1])),
                  !this.route.snapshot.queryParams.method && !this.route.snapshot.queryParams.au)
                )
                  return void this.router.navigate(['/access_denied'])
                const r = decodeURIComponent(this.route.snapshot.queryParams.au),
                  o = new URLSearchParams(r).get('uid') || ''
                if (!o) return void this.router.navigate(['/access_denied'])
                const e = this
                this.sharedService.getTransaction(o).subscribe({
                  next(a) {
                    if (a?.data?.id)
                      if ('rd' !== e.route.snapshot.queryParams.method.toLowerCase())
                        if ('dfiq' !== e.route.snapshot.queryParams.method.toLowerCase())
                          e.router.navigate(['/access_denied'])
                        else {
                          if (a.data.opinonRouteResp)
                            return (
                              (e.document.location.href = r),
                              void (r.includes('#') && e.document.location.reload())
                            )
                          const s = {
                            surveyId: e.route.snapshot.queryParams.sid,
                            grpId: e.route.snapshot.queryParams.gpid,
                            token: e.route.snapshot.queryParams.tk,
                            dgfp: e.route.snapshot.queryParams.dgfp,
                            channel: e.route.snapshot.queryParams.spid,
                            cntCode: e.route.snapshot.queryParams.cc,
                            au: e.route.snapshot.queryParams.au,
                            opnRtSndDate: new Date(),
                          }
                          loadCleanId(
                            s.token,
                            s.surveyId,
                            s.channel,
                            e.env.CLEAN_ID_DATA_KEY,
                            s.cntCode,
                          )
                            .then((u) => {
                              e.isCleanIdRespExist = !0
                              const c = JSON.parse(JSON.stringify({ forensic: u.forensic }))
                              if (!e.isCleanIdTimeoutErr) return e.saveCleanIdResponse(c, s, !1, !1)
                            })
                            .catch((u) => {
                              e.isCleanIdRespExist = !0
                              const c = JSON.parse(JSON.stringify({ forensic: u.error }))
                              if (!e.isCleanIdTimeoutErr) return e.saveCleanIdResponse(c, s, !0, !1)
                            })
                        }
                      else {
                        if (a.data.smplChnResp)
                          return (
                            (e.document.location.href = r),
                            void (r.includes('#') && e.document.location.reload())
                          )
                        let u, c
                        const l =
                          e.env.researchDefender.activityURL +
                          e.route.snapshot.queryParams.supCodeId
                        e.sharedService
                          .rdActivityAPICall(l, {
                            type: 'GET',
                            dataType: 'json',
                            contentType: 'application/json',
                            xhrFields: e.env.researchDefender.xhrFields,
                            headers: e.env.researchDefender.headers,
                            timeout: e.env.researchDefender.activityTimeout,
                          })
                          .subscribe(
                            (n) => {
                              ;(u = n), e.rdGetTokenAPICall(u, !0, !1)
                            },
                            (n) => {
                              const p = 'TimeoutError' === n.name || 'timeout' === n.name
                              ;(c = {
                                status: p ? 'timeout' : 'error',
                                message: p
                                  ? 'Activity Timeout Error From research defender'
                                  : 'Activity Error From research defender',
                                response: {
                                  url: JSON.stringify(l),
                                  isTimeOut: p,
                                  xhrRequest: {
                                    status: n.status >= 0 ? n.status : '',
                                    readyState: n.readyState || '',
                                    response: n.response || '',
                                    responseText: n.responseText ? JSON.parse(n.responseText) : '',
                                    responseType: n.responseType || '',
                                    responseURL: n.responseURL || '',
                                    statusText: n.statusText || '',
                                    timeout: p,
                                  },
                                },
                              }),
                                e.rdGetTokenAPICall(c, !1, p)
                            },
                          )
                      }
                    else e.router.navigate(['/access_denied'])
                  },
                  error(a) {
                    e.router.navigate(['/access_denied'])
                  },
                })
              }
              rdGetTokenAPICall(r, t, o) {
                this.sharedService
                  .rdGetTokenAPI(this.env.researchDefender.getTokenAPI, {
                    type: 'GET',
                    contentType: 'application/json',
                    xhrFields: { withCredentials: !0 },
                    timeout: this.env.researchDefender.getTokenTimeout,
                  })
                  .subscribe(
                    (a) => {
                      this.saveResearchDefenderResp(a, !0, !1, r, t, o)
                    },
                    (a) => {
                      let s = 'TimeoutError' === a.name
                      const u = {
                        status: s ? 'timeout' : 'error',
                        message: s
                          ? 'Timeout Error From Research Defender'
                          : 'Error From Research Defender',
                        response: {
                          url: JSON.stringify(this.env.researchDefender.getTokenAPI),
                          isTimeOut: s,
                          xhrRequest: {
                            status: a.status >= 0 ? a.status : '',
                            readyState: a.readyState || '',
                            response: a.response || '',
                            responseText: a.responseText ? JSON.parse(a.responseText) : '',
                            responseType: a.responseType || '',
                            responseURL: a.responseURL || '',
                            statusText: a.statusText || '',
                            timeout: s,
                          },
                        },
                      }
                      this.saveResearchDefenderResp(u, !1, s, r, t, o)
                    },
                  )
              }
              saveResearchDefenderResp(r, t, o, e, a, s) {
                if (!r && !e) return void this.router.navigate(['/access_denied'])
                  console.log(this.route.snapshot.queryParams);
                const u = {
                  token: this.route.snapshot.queryParams.token,
                  isQuesExist: this.route.snapshot.queryParams.isQuesExist,
                  isRDActvtyTimeout: s,
                  isRDGetTokenTimeout: o,
                  fingerPrintLevel: this.route.snapshot.queryParams.digitalFingerPrinting,
                  grpId: this.route.snapshot.queryParams.grp_id,
                  jobId: this.route.snapshot.queryParams.jb_id,
                  allowSt: this.route.snapshot.queryParams.allowSt,
                  // allowSt: "1,2,3,4,8,6",
                  surveyId: this.route.snapshot.queryParams.surveyId,
                  actualUrl: decodeURIComponent(this.route.snapshot.queryParams.au),
                  // thrtPtntlScore: this.route.snapshot.queryParams.threatPotentialScore,
                  thrtPtntlScore: "30",
                  supCode: this.route.snapshot.queryParams.supCode || 'FEsupplier',
                  PID: this.route.snapshot.queryParams.PID || '',
                  // getTokenAPIData:{
                  //   "results": [
                  //     {
                  //       "message": "Token successfully generated",
                  //       "timestamp": "2025-03-21 15:35:42.876644 [UTC] ",
                  //       "token": "f64759d875442dd1a326239d9b22120f4bccb957c15f8ec790885a4e83b341f6"
                  //     },
                  //   ]
                  // }
                };
                (u[t ? "getTokenAPIData" : "rdGetTokenError"] = r),
                  (u[a ? "actvtyAPIData" : "rdActvtyError"] = e),
                  this.sharedService.saveResearchDefenderResp(u).subscribe((n) => {
                    console.log('n.data', n.data);
                    if (n.data) {
                      if (n.data.checkRFGDuplicates) return void this.callRFGFingerPrint()
                      if (n.data.url)
                        return (
                          (this.document.location.href = n.data.url),
                          void (n.data.url.includes('#') && this.document.location.reload())
                        )
                    }
                    this.router.navigate(['/access_denied'])
                  })
              }
              saveCleanIdResponse(r, t, o, e) {
                const a = {
                  sid: t.surveyId,
                  tk: t.token,
                  spid: t.channel,
                  gpid: t.grpId,
                  dgfp: t.dgfp,
                  au: decodeURIComponent(t.au),
                  cleanIDResp: o ? '' : r,
                  cleanIDError: o ? r : '',
                  isOpinionRuteTimeOut: e,
                  opinionRouteStrtDateTime: t.opnRtSndDate,
                  opinionRouteEndDateTime: new Date(),
                }
                this.sharedService.saveCleanIdResponse(a).subscribe((s) => {
                  if (s.data) {
                    if (s.data.checkRFGDuplicates) return void this.callRFGFingerPrint()
                    if (s.data.url)
                      return (
                        (this.document.location.href = s.data.url),
                        void (s.data.url.includes('#') && this.document.location.reload())
                      )
                  }
                  this.router.navigate(['/access_denied'])
                })
              }
              callRFGFingerPrint() {
                loadRFG().then((r) => {
                  const t = {
                    fingerPrint: r.fingerPrint,
                    token:
                      this.route.snapshot.queryParams.tk || this.route.snapshot.queryParams.token,
                    surveyId:
                      this.route.snapshot.queryParams.sid ||
                      this.route.snapshot.queryParams.surveyId,
                    grpId:
                      this.route.snapshot.queryParams.gpid ||
                      this.route.snapshot.queryParams.grp_id,
                    channel:
                      this.route.snapshot.queryParams.spid ||
                      this.route.snapshot.queryParams.supCode,
                    au: decodeURIComponent(this.route.snapshot.queryParams.au),
                  }
                  this.sharedService.saveRFGFpAPICall(t).subscribe((o) => {
                    if (o.data && o.data.url)
                      return (
                        (this.document.location.href = o.data.url),
                        void (o.data.url.includes('#') && this.document.location.reload())
                      )
                    this.router.navigate(['/access_denied'])
                  })
                })
              }
              static {
                this.ɵfac = function (t) {
                  return new (t || d)(i.rXU(m.Ix), i.rXU(m.nX), i.rXU(v.d), i.rXU(f.qQ))
                }
              }
              static {
                this.ɵcmp = i.VBU({
                  type: d,
                  selectors: [['app-security-check']],
                  decls: 7,
                  vars: 0,
                  consts: [
                    [
                      1,
                      'row',
                      2,
                      'display',
                      'flex',
                      'height',
                      '100%',
                      'justify-content',
                      'center',
                      'align-items',
                      'center',
                    ],
                    [1, 'col-md-8', 'col-md-offset-2'],
                    [1, 'text-center'],
                    [
                      'ng-if',
                      'rtlLangCheck == 0',
                      1,
                      'text-center',
                      2,
                      'padding-top',
                      '10px',
                      'text-align',
                      'center',
                    ],
                    [
                      'ng-if',
                      'rtlLangCheck == 1',
                      'dir',
                      'rtl',
                      1,
                      'text-center',
                      2,
                      'padding-top',
                      '10px',
                    ],
                    ['id', 'pixelImg', 2, 'height', '1px'],
                  ],
                  template: function (t, o) {
                    1 & t &&
                      (i.j41(0, 'div', 0)(1, 'div', 1),
                      i.nrm(2, 'h1', 2),
                      i.j41(3, 'h4', 3),
                      i.EFF(4, 'Please Wait, Redirecting...'),
                      i.k0s(),
                      i.nrm(5, 'h4', 4)(6, 'div', 5),
                      i.k0s()())
                  },
                })
              }
            }
            return d
          })(),
        },
      ]
      let I = (() => {
        class d {
          static {
            this.ɵfac = function (t) {
              return new (t || d)()
            }
          }
          static {
            this.ɵmod = i.$C({ type: d })
          }
          static {
            this.ɵinj = i.G2t({ imports: [f.MD, m.iI.forChild(g)] })
          }
        }
        return d
      })()
    },
  },
])
